// const jwt = require('jsonwebtoken');
const {errorsModel} =require('../models/errorsModel');
//删除
async function deleteErrors(req, res, next) {
    //数据传过来就是id，那直接可以把id结构出来
    const data=req.body;
    const result=await errorsModel.deleteOne(data);
    if(result.deleteCount!=0){
        res.send({
            code:200,
            message:'删除成功'
        });
    }else{
        res.send({
            code:500,
            message:'删除失败'
        })
    }
  }

  //获取
  async function getErrors(req,res,next){
      const data = req.query;
      const result=await errorsModel.find(data).populate('errorQuestions_id');
      if(result.length>0){
          res.send({
              code:200,
              message:'数据获取成功',
              result
          })
      }else{
          res.send({
              code:500,
              message:'获取数据失败'
          })
      }
  }
//   添加
async function createErrors(req,res,next){
    const data=req.body;
    const result=await errorsModel.create(data);
    if(result!=null){
        res.send({
            code:200,
            message:'添加成功'
        })
    }else{
        res.send({
            code:500,
            message:'添加失败'
        })
    }
}
  module.exports={
    deleteErrors,getErrors,createErrors
}